<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>文件信息修改</title>
    <link rel="stylesheet" th:href="@{/myconfig/layui/css/layui.css}" media="all">
    <style>
        body{margin: 20px 20px 20px 0;}
        .demo-carousel{height: 200px; line-height: 200px; text-align: center;}
    </style>
</head>
<body>
<form class="layui-form" action="" lay-filter="updateForm">
    <input type="hidden" id="fileId" name="fileId" value=""/>
    <div class="layui-form-item">
        <label class="layui-form-label">文件名</label>
        <div class="layui-input-block">
            <input type="text" lay-filter="fileName" name="fileName" lay-verify="required" placeholder="请输入项目名" autocomplete="off" class="layui-input" disabled>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所属事项</label>
        <div class="layui-input-inline">
            <select name="itemId" id="itemName" lay-filter="itemName" lay-verify="required">

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文件类型</label>
        <div class="layui-input-block">
            <input type="text" lay-filter="fileTypeName" name="fileTypeName" lay-verify="required" autocomplete="off" class="layui-input" disabled>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">是否公开</label>
        <div class="layui-col-md12">
            <input type="checkbox" name="fileState" lay-filter="switchTest" lay-skin="switch" lay-text="公开|未公开">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">上传时间</label>
        <div class="layui-input-inline">
            <input type="text" name="fileTime" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" disabled>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">文件备注</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入文件备注" class="layui-textarea" lay-filter="fileContent" lay-verify="required" name="fileContent"></textarea>
        </div>
    </div>
    <div class="layui-form-item" style="margin-top: 10px;">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo1">立即提交</button>
        </div>
    </div>
</form>
<script th:src="@{/myconfig/layui/layui.js}"></script>

<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,$ = layui.$;

        //日期
        laydate.render({
            elem: '#date'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //监听提交
        form.on('submit(demo1)', function(data){
            /*layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })*/
            //var fileId = data.field;
            $.ajax({
                type:'post'
                ,url:'fileoper/update'
                ,data:data.field
                ,success:function (data,index) {
                    layer.msg(data.message,{icon:6},function () {
                        window.parent.location.reload();
                        parent.layer.close(index);
                    })
                }
            });
            return false;
        });

    });

    //数据回显
    function init(fileId) {
        // alert(businessProjectId + ";" + projectName+ ";" +projectContent+ ";" +projectTime+ ";" +countyName+ ";" +industryName+ ";" +projectStatusName+ ";" +statusName);
        //alert("文件id"+fileId);
        layui.use(['form', 'layedit', 'laydate'], function(){
            var form = layui.form,
                $ = layui.$;

            //文件信息
            $.ajax({
                url:'fileshow/findFileData'
                ,data:{fileId:fileId}
                ,success:function (BP) {
                    form.val('updateForm',{
                        "fileId":BP.fileId
                        ,"fileName":BP.fileName
                        ,"fileTime":BP.fileTime
                        ,"itemName":BP.itemName
                        ,"fileTypeName":BP.fileTypeName
                        ,"fileState":BP.checked
                        ,"fileContent":BP.fileContent
                    })
                   // alert(BP.fileTypeId+"，"+BP.itemId);
                    //所属事项
                    $("#itemName").val(BP.itemId);
                    $.ajax({
                        url:'fileshow/findMsg'
                        ,type:'post'
                        ,data:{
                            itemId:BP.itemId
                        }
                        ,success:function (result) {
                            var selectId = document.getElementById("itemName");
                            for (var i =0;i<result.length;i++){
                                var option1 =document.createElement("option");
                                option1.setAttribute("value",result[i].itemId);
                                option1.innerText = result[i].itemName;
                                selectId.appendChild(option1);
                                layui.form.render('select');
                            }
                        }
                    })

                }
            })
        })
    }
</script>
</body>
</html>